﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yule8xCommon.Applib;
using Yule8xCommon.Db;

namespace Yule8xWechat.Test
{
    public partial class Default : System.Web.UI.Page
    {
        protected int user_id, top_agent_id, parent1_uid, parent2_uid, top_agent_user_id;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                user_id = RequestUtil.GetInteger("user_id");
                if (user_id > 0)
                {
                    string sqlstmt = string.Format("SELECT u.parent1_uid, u.parent2_uid, u.top_agent_id, a.user_id as top_agent_user_id FROM t_user u LEFT JOIN dbo.t_user_agent a ON u.top_agent_id=a.top_agent_id where u.user_id={0}", user_id);
                    DataTable dtUser = DbFactory.Init(AppInfo.conn_yule8x_agent).ExecuteDataTable(sqlstmt);
                    if (dtUser.Rows.Count > 0)
                    {
                        parent1_uid = DataTableUtil.GetInteger(dtUser, "parent1_uid");
                        parent2_uid = DataTableUtil.GetInteger(dtUser, "parent2_uid");
                        top_agent_id = DataTableUtil.GetInteger(dtUser, "top_agent_id");
                        top_agent_user_id = DataTableUtil.GetInteger(dtUser, "top_agent_user_id");
                    }
                }
                tb_uid.Value = user_id.ToString();
            }
        }

        protected void btnSetting_Click(object sender, EventArgs e)
        {
            string user_id = tb_uid.Value;
            Response.Redirect(string.Format("Default.aspx?user_id={0}", (string.IsNullOrEmpty(user_id) ? "" : user_id)));
        }
    }
}